﻿// -------------------------------------------------------------------------
//    @FileName         :    NFQuestPart.h
//    @Author           :    gaoyi
//    @Date             :    2025/1/13
//    @Email            :    445267987@qq.com
//    @Module           :    NFQuestPart
//
// -------------------------------------------------------------------------

#pragma once

#include <NFComm/NFShmStl/NFShmBitMap.h>
#include <NFLogicCommon/NFBaseDefine.h>
#include <NFLogicCommon/NFLogicShmTypeDefines.h>
#include "NFPart.h"
#include "proto_city.pb.h"
#include "proto_common_quest.nanopb.h"
#include "proto_cs_login.pb.h"
#include "QuestDescEx.h"

struct RoleOne;

namespace proto_ff
{
    class tbRoleDetail;
}

class NFQuestPart : public NF_OBJECT_TEMPLATE_MACRO(NFQuestPart, EOT_LOGIC_PART_MIN_ID + PART_QUEST, NFPart)
public:
    NFQuestPart();

    ~NFQuestPart() override;

    int CreateInit();
    int ResumeInit();

public:
    //******************part调用接口******************
    /**
     * @brief 所有部件初始化完成
     * @return
     */
    int OnInit() override { return 0; }

public:
    /**
     * @brief 从数据库中加载数据
     * @param data
     * @return
     */
    int LoadFromDB(const proto_ff::tbRoleDetail* pDBData) override;

    /**
     * @brief 从配置中初始化数据
     * @return
     */
    int InitConfig(proto_ff::tbRoleDetail* pDbData, const RoleOne& stRoleOne) override;

    /**
     * @brief 存储DB部件入口
     * @param proto
     * @return
     */
    int SaveDB(proto_ff::tbRoleDetail* pDBData) override;

    /**
    * @brief 注册后的初始化
    * @return
    */
    int OnRegister() override;

    /**
     * @brief 登陆入口
     * @return
     */
    int OnLogin() override { return 0; }

    /**
     * @brief 登出入口
     * @return
     */
    int OnLogout() override { return 0; }

    /**
     * @brief 掉线入口
     * @return
     */
    int OnDisconnect() override { return 0; }

    /**
     * @brief 重连入口
     * @return
     */
    int OnReconnect() override { return 0; }

    ////////////////////////////////// 每日零点 每周一零点 刷新接口 ///////////////////////////////////
    /**
     * @brief 每日零点 刷新接口
     * @return
     */
    int DayTick() override { return 0; }

    /**
     * @brief 每日零点 刷新接口
     * @return
     */
    int WeekTick() override { return 0; }

    /**
     * @brief 每月刷新接口
     * @return
     */
    int MonthTick() override { return 0; };

public:
    /**
     * @brief update
     */
    int LogicTick() override { return 0; }

public:
    int MakePlayerDataCS(proto_ff::Proto_CSGetRoleRsp* pCSGetRoleRsp) override;
    int MakeCityPlayerData(proto_ff::CityRoleInfo* pGCCityRoleInfo) override;
    int MakeCityPlayerData(proto_ff::CityRoleQuestData* pGCCityRoleInfo);
    int GetTitle2() { return m_stData.title2_data.current_title; }

public:
    QuestNode* GetQuestNode(int iQuestID);
    QuestNode* AddQuestNode(int iQuestID);
    int DelQuestNode(int iQuestID);

public:
    LoopQuest* GetLoopQuest(int iLoopID);
    LoopQuest* AddLoopQuest(int iLoopID);
    int DelLoopQuest(int iLoopID);

public:
    LoopQuestFinishedNode* GetLoopQuestHis(int iID);

public:
    bool IsFinished(int iQuestID) const { return m_finished_quest.IsBitSetted(iQuestID); }

    void FinishQuest(int iQuestID);

public:
    QuestFinishCount* FindQuestCount(int iQuestID);
    QuestFinishCount* InsertQuestCount(int iQuestID);
    int GetQuestCount(int iQuestID);
    int AddQuestCount(int iQuestID);

private:
    uint32_t m_iNextDay;
    uint32_t m_iNextCleanTime;
    uint32_t m_iNextIntrustRefleshTime;
    RoleQuestData m_stData;
    NFShmBitMap<MAX_QUEST_ID_VALUE> m_finished_quest;
    NFShmBitMap<MAX_ACHIEVE_ID_VALUE> m_finished_achieve;
    NFShmBitMap<MAX_ACHIEVE_REWARD_ID_VALUE> m_achieve_reward;
};
